package com.hnkywl.sts.action.cwgl;

import com.hnkywl.sts.entity.organ.Nbgs;
import com.hnkywl.sts.entity.sfgl.Sfk;
import com.hnkywl.sts.entity.sys.Gncz;
import com.hnkywl.sts.entity.sys.Yg;
import com.hnkywl.sts.service.cwgl.SkdrService;
import com.hnkywl.sts.service.organ.GsjgService;
import com.hnkywl.sts.service.sys.GnczService;
import com.hnkywl.sts.service.sys.YgService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by HL on 2015/9/23.
 */
@Namespace("/cwgl/skdr")
public class SkdrAction extends SimpleActionSupport {
    private String sysDate;
    private Date sysdate = new Date();
    private SkdrService skdrService;
    private GsjgService gsjgService;
    private GnczService gnczService;
    private YgService ygService;
    private Date skshEnd;
    private Date skshStart;
    private Long skshId;
    private String zt;
    //单据号码
    private String bm;
    //申报公司机构名称
    private String sbgs;
    //申报公司机构Id
    private Long sbgsId;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows = 10;
    //收付款实例
    private Sfk skdr;
    private String gldwMc;

    private Long gldwId;
    private String skr;
    private List<Gncz> gnczList;
    private String bzjdrpjlxMc;
    private Integer skdrZt;
    private Yg yg;
    private String gsmc;
    private Long skdrId;
    private String systemDate;
    private Sfk sfk;
    private Map<String, Object> voucherMaster = new HashMap<String, Object>();
    private Integer attachment;


    @Action("skdr")
    public String bzjdr() {
        gnczList = gnczService.findGnczByJsAndUrl(request.getServletPath());
        return SUCCESS;
    }

    @Action("skdrList")
    public void skdrList() {
        this.renderJson(this.skdrService.findAllSkdr(skshStart, skshEnd, bm, bzjdrpjlxMc, sbgs, sbgsId, gldwMc, zt, skdrZt, skr, page, rows));
    }

    @Action("skdr_detail")
    public String skshContent() {
        Yg yg = YgService.getCurrentYg();
        Long gsId = YgService.getCurrentYgGsId();
        Long zggsId = YgService.getCurrentYgZgGsId();
        //进入update页面
        if (skshId != null) {
            skdr = skdrService.findskdrDetail(skshId);
        } else {
            skdr = new Sfk();
            skdr.setSbr(yg);
            skdr.setSbgs((Nbgs) gsjgService.findGsjgDetail(zggsId));
        }
        return SUCCESS;
    }

    // 生成凭证页面
    @Action("skdr_content")
    public String bzjdrContent() {
        yg = ygService.findYgDetail(YgService.getCurrentYg().getId());
        gsmc = this.skdrService.findSkdrDetail(skdrId).getSbgs().getQc();
        DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
        systemDate = fmt.format(new Date());
        sfk = this.skdrService.findSkdrDetail(skdrId);
        voucherMaster = this.skdrService.getVoucherMaster(skdrId, attachment, null, null, null, yg);
        return SUCCESS;
    }

    //查询财务收付分录
    @Action("findSkdrfl")
    public void findSkdrfl() {
        renderText(skdrService.findSkdrfl(skdrId));
    }


    //========================================================


    public Long getSkdrId() {
        return skdrId;
    }

    public void setSkdrId(Long skdrId) {
        this.skdrId = skdrId;
    }

    public String getSystemDate() {
        return systemDate;
    }

    public void setSystemDate(String systemDate) {
        this.systemDate = systemDate;
    }

    public Sfk getSfk() {
        return sfk;
    }

    public void setSfk(Sfk sfk) {
        this.sfk = sfk;
    }

    public Map<String, Object> getVoucherMaster() {
        return voucherMaster;
    }

    public void setVoucherMaster(Map<String, Object> voucherMaster) {
        this.voucherMaster = voucherMaster;
    }

    public Integer getAttachment() {
        return attachment;
    }

    public void setAttachment(Integer attachment) {
        this.attachment = attachment;
    }

    public String getGsmc() {
        return gsmc;
    }

    public void setGsmc(String gsmc) {
        this.gsmc = gsmc;
    }

    public List<Gncz> getGnczList() {
        return gnczList;
    }

    public void setGnczList(List<Gncz> gnczList) {
        this.gnczList = gnczList;
    }

    public Date getSysdate() {
        return sysdate;
    }

    public void setSysdate(Date sysdate) {
        this.sysdate = sysdate;
    }

    public String getSysDate() {
        return sysDate;
    }

    public void setSysDate(String sysDate) {
        this.sysDate = sysDate;
    }

    public Date getSkshEnd() {
        return skshEnd;
    }

    public void setSkshEnd(Date skshEnd) {
        this.skshEnd = skshEnd;
    }

    public Date getSkshStart() {
        return skshStart;
    }

    public void setSkshStart(Date skshStart) {
        this.skshStart = skshStart;
    }

    public Long getSkshId() {
        return skshId;
    }

    public void setSkshId(Long skshId) {
        this.skshId = skshId;
    }

    public String getZt() {
        return zt;
    }

    public void setZt(String zt) {
        this.zt = zt;
    }

    public String getBm() {
        return bm;
    }

    public void setBm(String bm) {
        this.bm = bm;
    }

    public String getSbgs() {
        return sbgs;
    }

    public void setSbgs(String sbgs) {
        this.sbgs = sbgs;
    }

    public Long getSbgsId() {
        return sbgsId;
    }

    public void setSbgsId(Long sbgsId) {
        this.sbgsId = sbgsId;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public Sfk getSkdr() {
        return skdr;
    }

    public void setSkdr(Sfk skdr) {
        this.skdr = skdr;
    }

    public String getGldwMc() {
        return gldwMc;
    }

    public void setGldwMc(String gldwMc) {
        this.gldwMc = gldwMc;
    }

    public Long getGldwId() {
        return gldwId;
    }

    public void setGldwId(Long gldwId) {
        this.gldwId = gldwId;
    }

    public String getSkr() {
        return skr;
    }

    public void setSkr(String skr) {
        this.skr = skr;
    }

    public String getBzjdrpjlxMc() {
        return bzjdrpjlxMc;
    }

    public void setBzjdrpjlxMc(String bzjdrpjlxMc) {
        this.bzjdrpjlxMc = bzjdrpjlxMc;
    }

    public Integer getSkdrZt() {
        return skdrZt;
    }

    public void setSkdrZt(Integer skdrZt) {
        this.skdrZt = skdrZt;
    }

    public Yg getYg() {
        return yg;
    }

    public void setYg(Yg yg) {
        this.yg = yg;
    }

    @Autowired
    public void setSkdrService(SkdrService skdrService) {
        this.skdrService = skdrService;
    }

    @Autowired
    public void setGsjgService(GsjgService gsjgService) {
        this.gsjgService = gsjgService;
    }

    @Autowired
    public void setGnczService(GnczService gnczService) {
        this.gnczService = gnczService;
    }

    @Autowired
    public void setYgService(YgService ygService) {
        this.ygService = ygService;
    }
}
